package com.fengye.algorithms.leecode;

/**
 * @Author fengye
 * @Date 2023/5/8 12:37
 **/
public class BitwiseAndOfNumbersRange201 {
    public int rangeBitwiseAnd1(int left, int right) {
        int n = 0;
        while ( left < right) {
            left = left >> 1;
            right = right >> 1;
            n++;
        }

        return left << n;
    }

    public int rangeBitwiseAnd(int m, int n) {
        while (m < n) {
            // 抹去最右边的 1
            n = n & (n - 1);
        }
        return n;
    }

}
